<template>
  <el-dialog title="评分配置"
             :visible.sync="visible"
             :before-close="modalClose"
             :append-to-body="true"
             :close-on-click-modal="false"
             :close-on-press-escape="false"
             width="60%">
    <element-table class="mt-20"
                   :columns="columns"
                   :data="tableData">
      <template v-slot:scroe="{row}">
        <el-select v-model="row.score"
                   class="w-300"
                   placeholder="请选择评分">
          <el-option v-for="item in scoringDataSource"
                     :key="item"
                     :label="item"
                     :value="item">
          </el-option>
        </el-select>

      </template>

    </element-table>
    <p align="center">
      <el-button @click="modalClose"
                 type="info">取 消
      </el-button>
      <el-button type="primary"
                 v-prevent-re-click
                 @click="handleSave()">保 存
      </el-button>
    </p>

  </el-dialog>
</template>

<script>
  import ElementTable from "../../../../base/ElementTable";

  export default {
    name: "dialogScore",
    props: {
      dataObj: {
        type: Object,
        default: {}
      },
      visible: {
        type: Boolean,
        default: false
      }
    },
    data() {
      return {
        tableData: [],
        scoringDataSource:[],
        columns: [
          {
            label: '指标状态',
            prop: 'indicationResult',
            align: 'center',
          }, {
            label: '评分',
            prop: 'scroe',
            align: 'center',
            isSlot:true
          }
        ]

      }
    },
    created() {
      if (this.dataObj.indicationType === 1) {
        this.columns[0].label = '指标状态'
      } else if (this.dataObj.indicationType === 2) {
        this.columns[0].label = '量表结论'
      } else if (this.dataObj.indicationType === 3) {
        this.columns[0].label = '判断结果'
      }
      this.getScoreList()
      this.getScoreDetail()
    },
    methods: {
      modalClose() {
        this.$emit('update:visible', false);
      },
      handleSave(){
        if (this.tableData.some(item=>!item.score)){
          this.$message.warning('请选择评分')
        }else {
          this.post(this.api.healthMap.setScore, {
            id: this.dataObj.id,
            resultsScore:this.tableData
          }).then((res) => {
            if (res.data.code === '200') {
              this.$message.success('保存成功')
              this.$parent.getList()
              this.modalClose()
            }
          })
        }
      },
      //详情
      getScoreDetail() {
        this.post(this.api.healthMap.getScoreDetail, {
          id: this.dataObj.id
        }).then((res) => {
          if (res.data.code === '200') {
            this.tableData = res.data.object.resultsScore
          }
        })
      },

      //查询得分
      getScoreList() {
        this.post(this.api.healthMap.getScoreList).then((res) => {
          if (res.data.code === '200') {
            this.scoringDataSource = res.data.object
          }
        })
      },
    },
    components: {
      'element-table': ElementTable
    }

  }
</script>

<style scoped>

</style>
